package org.aspectsense.middleware.scheduler;

/**
 * @author Nearchos Paspallis [nearchos@cs.ucy.ac.cy]
 *         Date: Feb 8, 2008
 *         Time: 11:55:14 AM
 */
public class RecurringEvent extends Event
{
    private final long interval;

    /**
     * Constructs a recurring scheduled event. Its semantics imply that the
     * specified runnable should be repeatedly executed after some time,
     * specified by the minWaitTime. For example, if the minWaitTime is
     * specified as 10000L, then the corresponding event is scheduled to start
     * execution after 10 seconds.Furthermore, once started, the specified
     * runnable should be executed every some time interval, as specified by
     * the minWaitTime argument. For example, if the minWaitTime is specified
     * as 5000L, then the corresponding event is scheduled for execution every
     * 5 seconds.
     *
     * @param runnable the {@link Runnable} to be executed
     * @param minWaitTime the time period after which the {@link Runnable}
     * should be executed; expressed in milliseconds
     * @param interval the time interval which specifies how often the {@link
     * Runnable} should be executed; expressed in milliseconds
     */
    public RecurringEvent(final Runnable runnable, final long minWaitTime, final long interval)
    {
        super(runnable, minWaitTime);

        if(interval <= 0)
        {
            throw new IllegalArgumentException("The interval cannot be "
                    + "negative or zero: " + interval);
        }

        this.interval = interval;
    }

    public long getInterval()
    {
        return interval;
    }

    public String toString()
    {
        return "RecurringEvent{runnable= " + runnable + ", minWaitTime="
                + minWaitTime + ", interval=" + interval + "}";
    }
}